var TableShopsPendding = function () {
    return {
        init: function () {
		         
            var oTable = $('#table_common').dataTable({
                "aLengthMenu": [
                    [-1,5, 15, 20],
                    ["全部",'5条', '15条', '20条'] 
                ],
                "iDisplayLength": -1,
				"serverSide":true,
				//"aaSorting":[[6,'desc']],
                "sPaginationType": "bootstrap",
				//"bStateSave": true, 
                "oLanguage": {
					"sSearch":"搜索",
                    "sLengthMenu": "每页显示 _MENU_ 记录",    
					"sEmptyTable":"没有数据",
					"sInfo": "当前数据为从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录",   
					"sInfoEmpty": "没有数据",   
					"sInfoFiltered" : "",
					"sInfoPostFix" : "",
					"sLoadingRecords":"",
					"sProcessing": "正在加载数据...", 
					"sZeroRecords": "没有检索到数据", 
                    "oPaginate": {   
						"sFirst": "首页",   
						"sPrevious": "上一页",   
						"sNext": "下一页",   
						"sLast": "尾页"  
					}   
                },
				"sAjaxSource":pendUrl,
				"sAjaxDataProp": "data",
				
				"aoColumns": [
	
					{"sTitle":'序号',"mDataProp": 'shopId'},
					{"sTitle":'店铺名称',"mDataProp": 'shopName'},
					{"sTitle":'店铺编号',"mDataProp": 'shopSn'},
					{"sTitle":'店主',"mDataProp": 'userName'},
					{"sTitle":'分类',"mDataProp": 'catName'},
					{"sTitle":'是否营业',"mDataProp": 'shopAtive'},
					{"sTitle":'店铺状态',"mDataProp": 'shopStatus'},
					{"sTitle":'操作',"mDataProp": 'shopFlag'}
				],
                "aoColumnDefs": [{
                        'bSortable': false,
						'aTargets': ['_all']
                },
				{"aTargets":[0],"sClass":'text-center',"sWidth":'5%'},
				/* {"aTargets":[0],"mRender":function(data,type,full){
					if(full['isOnline']==1){
						if(full['enabled']==1){						
							return data+' <a class="delpay btn btn-xs default" href=""><i class="fa fa-cog"></i> 卸载</a>';						
						}else{
							return data+' <a class="editpay btn btn-xs blue" href=""><i class="fa fa-cog"></i> 安装</a>';
						}						
                    }else{
						return data;
					}
				}},
				{"aTargets":[4],"mRender":function(data,type,full){						
					if(data==1){						
						return '<span class="isonline btn btn-xs blue">在线支付</span>';						
					}else{
						return '<span class="online btn btn-xs default">线下支付</span>';
					}						
                    },"sClass":'text-center'}, */
				{"aTargets":[5],"mRender":function(data,type,full){						
					if(data==1){						
						return '<span class="isonline btn btn-xs blue">营业</span>';						
					}else{
						return '<span class="online btn btn-xs default">休息</span>';
					}						
                    },"sClass":'text-center'},
				{"aTargets":[6],"mRender":function(data,type,full){						
					if(data==0){						
						return '<span class="isonline btn btn-xs blue">未审核</span>';						
					}else if(data==-1){
						return '<span class="online btn btn-xs red">已拒绝</span>';
					}else{
						return '<span class="online btn btn-xs default">已停止</span>';
					}						
                    },"sClass":'text-center'},
				{"aTargets":[7],"mRender":function(data,type,full){
					if(full['shopStatus']==0){
						html= '<a class="yes btn btn-xs green" href=""><i class="fa fa-check"></i> 通过</a><a class="no btn btn-xs red" href=""><i class="fa fa-ban"></i> 拒绝</a> ';
					}else{
						html = '';
					}
					return html+'<a class="edit btn btn-xs default" href=""><i class="fa fa-edit"></i> 修改</a><a class="delete btn btn-xs red" href=""><i class="fa fa-trash-o"></i> 删除</a>';
                    },"sWidth":'5%'}
				],
				"fnCreatedRow":function(nRow,aData,iDataIndex){
					$('td:eq(0)',nRow).html(iDataIndex+1);//为第一个单元格增加序号
				}				
            });

            jQuery('#table_common_wrapper .dataTables_filter input').addClass("form-control input-medium input-inline"); // modify table search input
            jQuery('#table_common_wrapper .dataTables_length select').addClass("form-control input-small"); // modify table per page dropdown
            jQuery('#table_common_wrapper .dataTables_length select').select2({
                showSearchInput : false 
            }); 
			
			var nEditing = null;
			
			//删除
            $('#table_common a.delete').live('click', function (e) {
				e.preventDefault();
				var nRow = $(this).parents('tr')[0];
				var aData = oTable.fnGetData(nRow);
				layer.confirm('确定删除该店铺？',function(index){
					$.post(ajaxUrl,{shopId:aData['shopId'],ajax:'delShops'},function(data){
						if(data){
							layer.msg('店铺删除成功！',{icon: 1,time: 2000});
							oTable.fnDeleteRow(nRow);
							
						}else{
							layer.msg('店铺删除失败！',{icon: 1,time: 2000});
							return;
						}
				   });					
				});	
                
            });
			
			//通过
            $('#table_common a.yes').live('click', function (e) {
				e.preventDefault();
				var nRow = $(this).parents('tr')[0];
				var aData = oTable.fnGetData(nRow);
				layer.confirm('确定直接审核通过该店铺？',function(index){
					$.post(ajaxUrl,{shopId:aData['shopId'],ajax:'startShops'},function(data){
						if(data){
							layer.msg('该店铺已审核通过！',{icon: 1,time: 2000});
							oTable.fnReloadAjax();
							
						}else{
							layer.msg('店铺状态未更改！',{icon: 2,time: 2000});
							return;
						}
				   });					
				});	
                
            });
			
			//拒绝
			
            $('#table_common a.no').live('click', function (e) {
				e.preventDefault();
				var nRow = $(this).parents('tr')[0];
				var aData = oTable.fnGetData(nRow);
				layer.ready(function(){
					layer.prompt({
						formType: 2,
						value: '',
						title: '请输入拒绝意见！'
					}, function(value, index, elem){
						$.post(ajaxUrl,{shopId:aData['shopId'],ajax:'stopShops',statusRemarks:value,shopStatus:-1},function(data){
							if(data){
								layer.msg('该店铺已拒绝！',{icon: 1,time: 2000});
								oTable.fnUpdate(shopStatus, nRow,6, false);
								oTable.fnDraw();
							}else{
								layer.msg('店铺状态未更改！',{icon: 2,time: 2000});
								return;
							}
					   });		
						layer.close(index);
					});
				});               
            });
			

			//修改
            $('#table_common a.edit').live('click', function (e) {
                e.preventDefault();
                var nRow = $(this).parents('tr')[0];
				var aData = oTable.fnGetData(nRow);
				var url=editUrl+'?shopId='+aData['shopId'];
				location.href=url;
            });
        }

    };

}();